package jlxy.ise.eroad.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.Toolbar;
import android.view.View;

import jlxy.ise.eroad.R;
import jlxy.ise.eroad.base.BaseCompatActivity;
import jlxy.ise.eroad.fragment.AboutFragment;
import jlxy.ise.eroad.fragment.ModifyPwdFragment;
import jlxy.ise.eroad.fragment.PersonFragment;
import jlxy.ise.eroad.util.C;


/**
 * @author chen
 */
public class MyInfoActivity extends BaseCompatActivity {

    private static final String TAG = MyInfoActivity.class.getSimpleName();

    private Toolbar toolbar;
    private String mTitle;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fragment);

        Intent it = getIntent();
        mTitle = it.getStringExtra(C.INTENT_TYPE.DATA_OBJ);
        initViews();
        if(mTitle.equals(getString(R.string.setting_about_app))){
            changeFragment(AboutFragment.getInstance());
        }else if(mTitle.equals(getString(R.string.setting_modify_personal))){
            changeFragment(PersonFragment.getInstance());
        }else{
            changeFragment(ModifyPwdFragment.getInstance());
        }
    }

    private void initViews() {
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setTitle(mTitle);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyInfoActivity.this.onBackPressed();
            }
        });
    }

    private void changeFragment(android.support.v4.app.Fragment targetFragment) {
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.frame_container, targetFragment, "fragment")
                .setTransitionStyle(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
                .commit();
    }

}
